#include "ImageDataProvider.h"
#include <QVariant>
#include <QCoreApplication>

ImageDataProvider::ImageDataProvider(ImageMappingManager* mappingManager, QObject* parent)
    : QObject(parent)
    , m_mappingManager(mappingManager)
{
}

QStringList ImageDataProvider::getHalconImagePaths() const
{
    QStringList paths;
    QString tempFolder = QCoreApplication::applicationDirPath()+"/halconImage";

    for (const QString& renamedFile : m_mappingManager->getRenamedImageFiles()) {
        paths.append(tempFolder + "/" + renamedFile);
    }

    return paths;
}

QMap<QString, QList<int>> ImageDataProvider::getHalconCoordinateMap() const
{
    QMap<QString, QList<int>> coordMap;

    for (const ImageFileInfo& info : m_mappingManager->getImageInfoList()) {
        QList<int> coords;
        coords << info.coordinate.fixtureRow
               << info.coordinate.fixtureCol
               << info.coordinate.fovRow
               << info.coordinate.fovCol;

        coordMap[info.renamedName] = coords;
    }

    return coordMap;
}

QMap<QString, QVariant> ImageDataProvider::getImageDataForDisplay() const
{
    QMap<QString, QVariant> data;

    for (const ImageFileInfo& info : m_mappingManager->getImageInfoList()) {
        QVariantMap imageData;
        imageData["originalName"] = info.originalName;
        imageData["renamedName"] = info.renamedName;
        imageData["fullPath"] = info.fullPath;
        imageData["fixtureRow"] = info.coordinate.fixtureRow;
        imageData["fixtureCol"] = info.coordinate.fixtureCol;
        imageData["fovRow"] = info.coordinate.fovRow;
        imageData["fovCol"] = info.coordinate.fovCol;
        imageData["coordinateString"] = info.coordinate.toString();

        data[info.originalName] = imageData;
    }

    return data;
}

// QList<QStringList> ImageDataProvider::getCoordinateTableData() const
// {
//     QList<QStringList> tableData;

//     // 表头
//     tableData << QStringList() << "原始文件名" << "重命名" << "治具行" << "治具列" << "FOV行" << "FOV列";

//     // 数据行
//     for (const ImageFileInfo& info : m_mappingManager->getImageInfoList()) {
//         QStringList row;
//         row << info.originalName
//             << info.renamedName
//             << QString::number(info.coordinate.fixtureRow)
//             << QString::number(info.coordinate.fixtureCol)
//             << QString::number(info.coordinate.fovRow)
//             << QString::number(info.coordinate.fovCol);

//         tableData << row;
//     }

//     return tableData;
// }
